package com.yellowpage.alarm.monitor;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.yellowpage.alarm.data.AlarmInfo;
import com.yellowpage.alarm.service.AlarmInfoService;
import com.yellowpage.white.exception.AlarmException;

/**
 * 监控告警信息处理类
 * 
 * @author leasass
 * 
 */
public class AlarmInfoMonitorTask {
	private Log log = LogFactory.getLog(this.getClass());
	/**
	 * 告警信息业务接口
	 */
	private AlarmInfoService alarmInfoService;

	public AlarmInfoService getAlarmInfoService() {
		return alarmInfoService;
	}

	public void setAlarmInfoService(AlarmInfoService alarmInfoService) {
		this.alarmInfoService = alarmInfoService;
	}

	public void process() {
		log.info("本次监控告警信息任务开始执行>>");
		List<AlarmInfo> alarmInfos = null;
		//查询需要处理的告警信息
		alarmInfos = this.alarmInfoService.getEffectiveAlarmInfos();

		if (null == alarmInfos || alarmInfos.isEmpty()) {
			log.info("没有需要处理的告警信息");
			log.info("本次监控告警信息任务执行完成>>");
			return;
		}

		for (AlarmInfo alarmInfo : alarmInfos) {
			try {
				this.alarmInfoService.alarm(alarmInfo);
			} catch (AlarmException e) {
				log.error("处理告警信息[" + alarmInfo.getId() + "]失败，失败原因为["
						+ e.getMessage() + "]", e);
				continue;
			}
		}

		log.info("本次监控告警信息任务执行完成>>");

	}

}
